package com.linkage.seapeak.adapter;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.linkage.jz.bankruptcy.R;
import com.linkage.seapeak.pojo.CrediterUser;
import com.linkage.seapeak.pojo.MultiMessage;
import com.linkage.seapeak.utils.CommonUtils;
import com.seapeak.recyclebundle.BaseHolder;
import com.seapeak.recyclebundle.BaseRecyclerAdapter;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import jp.wasabeef.glide.transformations.CropCircleTransformation;

public class ItemNewHistoryAdapter extends BaseRecyclerAdapter<ItemNewHistoryAdapter.ViewHolder> {

    Context context;
    List<MultiMessage> multiMessageList;


    public ItemNewHistoryAdapter(Context context, List<MultiMessage> multiMessageList) {
        this.context = context;
        this.multiMessageList = multiMessageList;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_new_multi_message, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        MultiMessage item = multiMessageList.get(position);
        if (item != null) {
            List<CrediterUser> users = item.getUsers();
//            addAvatar(holder.avatarParent, users);
            String userNameStr = "";
            for (int i = 0;i < item.getUserCount();i++) {
                if (i > 3) {
                    userNameStr += "等" + item.getUserCount() + "人";
                    break;
                }
                CrediterUser user = users.get(i);
                if (i != 0)
                    userNameStr += "，";
                userNameStr += user.getCreditorname();
            }

            holder.userName.setText("接收者：" + userNameStr);
            holder.desc.setText("发送人：" + item.getSendUserName());
            String timeStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(((long) item.getOpAt()) * 1000L));
            holder.sendTime.setText(CommonUtils.resetTime(timeStr));
            holder.msgContent.setText(item.getNote());
        }
    }

    @Override
    public int getItemCount() {
        return multiMessageList.size();
    }


    /**
     * 群发历史消息展示
     */
    class ViewHolder extends BaseHolder {

        private TextView desc;
        private TextView sendTime;
        private TextView userName;
        private TextView msgContent;

        public ViewHolder(View view) {
            super(view);
            desc = (TextView) view.findViewById(R.id.desc);
            sendTime = (TextView) view.findViewById(R.id.send_time);
            userName = (TextView) view.findViewById(R.id.user_name);
            msgContent = (TextView) view.findViewById(R.id.msg_content);
        }
    }
}
